// IOI 2009 Regions

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
struct Emp {
  int tin, reg;
  vi ch;  // 被指导的
};
struct Reg {
  vi ids;             // 其中的Employee
  vector<pi> ranges;  // {id, cnt}
  int cnt;
};
vector<Emp> ES;
vector<Reg> RS;
void dfs(int u, int &timer) {
  auto &r = RS[ES[u].reg];
  r.ids.push_back(timer++), r.ranges.push_back({timer, ++r.cnt});
  for (int v : ES[u].ch) dfs(v, timer);
  r.ranges.push_back({timer, --r.cnt});
}
ll query_by_id(const Reg &r1, const Reg &r2) {
  ll ans = 0;
  auto &rv = r1.ranges;
  for (int u : r2.ids) {
    auto it = lower_bound(begin(rv), end(rv), make_pair(u, INT_MAX));
    if (it != rv.begin()) ans += prev(it)->second;
  }
  return ans;
}
ll query_by_range(const Reg &r1, const Reg &r2) {
  ll ans = 0;
  const auto &rv = r2.ids;
  for (size_t i = 0; i + 1 < r1.ranges.size(); ++i) {
    int p1 = r1.ranges[i].first, p2 = r1.ranges[i + 1].first;
    auto it1 = lower_bound(begin(rv), end(rv), p1),
         it2 = lower_bound(begin(rv), end(rv), p2);
    ans += r1.ranges[i].second * (it2 - it1);
  }
  return ans;
}
ll solve(int r1, int r2) {
  static map<pi, ll> M;
  pi k(r1, r2);
  if (M.count(k)) return M[k];
  const Reg &reg1 = RS[r1], &reg2 = RS[r2];
  int s1 = reg1.ids.size(), s2 = reg2.ids.size();
  int tm1 = (log2(s2) + 2) * s1, tm2 = (log2(s1) + 2) * s2;
  ll ans = tm1 < tm2 ? query_by_range(reg1, reg2) : query_by_id(reg1, reg2);
  return M[k] = ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int N, R, Q, timer = 0;
  cin >> N >> R >> Q, ES.resize(N), RS.resize(R);
  cin >> ES[0].reg, --ES[0].reg;
  for (int i = 1, fa; i < N; ++i)
    cin >> fa >> ES[i].reg, --ES[i].reg, ES[fa - 1].ch.push_back(i);
  dfs(0, timer);
  for (int q = 0, r1, r2; q < Q; ++q)
    cin >> r1 >> r2, cout << solve(r1 - 1, r2 - 1) << endl;
  return 0;
}
